package com.onegroup.pojo;

import com.onegroup.common.enums.ResponseStatusEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author: 曾雪斌
 * @Description: 响应结果集
 * @History:
 */
@NoArgsConstructor
@AllArgsConstructor
@Data
public class ResponseResult<T> {

    /**
     * 状态码
     */
    private int code;
    /**
     * 状态类型
     */
    private String status;
    /**
     * 状态信息
     */
    private String msg;
    /**
     * 后端数据
     */
    private T data;

    public ResponseResult(ResponseStatusEnum responseStatusEnum) {
        this.code = responseStatusEnum.getCode();
        this.status = responseStatusEnum.getStatus();
        this.msg = responseStatusEnum.getMsg();
    }

    public static <T> ResponseResult<T> success(String msg) {
        ResponseResult<T> responseResult = new ResponseResult<>(ResponseStatusEnum.SUCCESS);
        responseResult.setMsg(msg);
        return responseResult;
    }

    public static <T> ResponseResult<T> success(T data) {
        ResponseResult<T> result = new ResponseResult<>(ResponseStatusEnum.SUCCESS);
        result.setData(data);
        return result;
    }

    public static <T> ResponseResult<T> failed(String msg) {
        ResponseResult<T> responseResult = new ResponseResult<>(ResponseStatusEnum.FAILED);
        responseResult.setMsg(msg);
        return responseResult;
    }

    public static <T> ResponseResult<T> failed(T data) {
        ResponseResult<T> result = new ResponseResult<>(ResponseStatusEnum.FAILED);
        result.setData(data);
        return result;
    }

}
